package com.itany.book.controller;

import com.github.pagehelper.PageInfo;
import com.itany.book.pojo.Examine;
import com.itany.book.pojo.User;
import com.itany.book.service.UserService;
import com.itany.book.vo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Author:yaozhiyuan0117@163.com
 * Time:2019/12/25 20:40
 * Describe:
 * version:1.0
 */

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("/findAll")
    @ResponseBody
    public Map findByPage(Integer page,
                           @RequestParam(defaultValue = "1")Integer rows,
                           String username,
                           Integer flag
    ){
        System.out.println("----------");
        System.out.println(username);
        System.out.println(flag);

        PageInfo<User> pageInfo = (PageInfo<User>) userService.findAll(page,rows,username,flag);
        Map map = new HashMap();
        map.put("total", pageInfo.getTotal());
        map.put("rows",pageInfo.getList());
        System.out.println(pageInfo.getList());
        return map;
    }


    @RequestMapping("/findById")
    @ResponseBody
    public ResponseResult findById(Integer id){

        User user = userService.findById(id);
        return ResponseResult.success(user);
    }

    @RequestMapping("/modifyUser")
    @ResponseBody
    public ResponseResult modifyUser(User user){
        System.out.println("------------");
        System.out.println(user.getId());
        userService.modifyUser(user);
        return ResponseResult.success();
    }

    // @RequestMapping("/modifyFlag")
    // @ResponseBody
    // public ResponseResult modifyFlag(User user){
    //     userService.modifyUser(user);
    //     return ResponseResult.success();
    // }
}
